package com.lz.football.module.goldpalace
{
	import com.common.utils.Reflection;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.goods.vo.GoodsVo;
	import com.lz.football.module.base.IComponent;
	import com.lz.football.module.goldpalace.item.AwardItem;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import lz.controls.ScrollPolicy;
	import lz.controls.containers.ScrollPane;

	/**
	 *奖励面板 
	 * @author lake
	 * 
	 */	
	public class AwardPanel extends Sprite implements IComponent
	{/**
		*皮肤 
		*/		
		protected var _symbolSkin		:MovieClip;
		/**
		 *关闭按钮 
		 */		
		private var closeBtn 			:SimpleButton;
		/**
		 *条目容器 
		 */		
		protected var itemContainer	:Sprite;
		/**
		 *条目list 
		 */		
		private var itemList		:Array = [];
		/**
		 *选中条目 
		 */		
		private var selectItem 	:AwardItem;
		
		public function AwardPanel()
		{
			super();
		}
		/**
		 *初始化 
		 * 
		 */	
		public function initUI(view:Object=null):void
		{
			_symbolSkin = Reflection.createInstance("com.lz.football.goldpalace.awardPanelSkin");
			this.addChild(_symbolSkin);
			closeBtn = _symbolSkin.closeBtn;
			itemContainer = new Sprite();
			addEvtListener();
		}
		/**
		 *初始化资源 
		 */		
		public function initRes():void
		{
			var scrollPanel :ScrollPane = new ScrollPane();
			scrollPanel.horizontalScrollPolicy = ScrollPolicy.OFF;
			scrollPanel.move(5,23);
			scrollPanel.setSize(147,282);
			var awardItem :AwardItem;
			var active :int = AppData.getInstance().goldPalaceManager.goldPalaceVo.active;
			var awardPos :int = AppData.getInstance().goldPalaceManager.goldPalaceVo.awardPos;
			var awards :Array = AppData.getInstance().goldPalaceManager.goldPalaceVo.awards;
			var timeS  :Array = ["1天","1天","1天","1天","1天","1天","2天","2天","3天","4天","5天","7天"];
			var goodsVo :GoodsVo;
			for(var i :int = 0;i<12;i++)
			{
				awardItem = new AwardItem();
				awardItem.initUI();
				itemContainer.addChild(awardItem);
				awardItem.y = i * 57;;
				goodsVo = AppData.getInstance().goodsManager.getGoodsByTypeAndId(awards[i].type,awards[i].id);
				awardItem.data = {goods:goodsVo,tstr:timeS[i],index:(i+1)};
				itemList.push(awardItem);
				if((i+1) > active)
				{
					awardItem.alpha = .5;
					awardItem.mouseChildren = false;
					//awardItem.mouseEnabled = false;
				}
			}
			if(awardPos > 0)
			{
				selectItem = itemList[awardPos - 1];
				selectItem.select();
			}
			scrollPanel.source = itemContainer;
			_symbolSkin.addChild(scrollPanel);
		}
		/**
		 *更换奖励 
		 * @param pos
		 * 
		 */		
		public function changeAward(pos :int):void
		{
			if(pos > 0)
			{
				if(selectItem)
				{
					selectItem.unSelect();
				}
				selectItem = itemList[pos - 1];
				selectItem.select();
			}
		}
		/**
		 * 激活球员 
		 * @param pos
		 * 
		 */		
		public function activePlayer(pos :int):void
		{
			if(pos > 0)
			{
				var awardItem :AwardItem = itemList[pos - 1];
				awardItem.alpha = 1;
				awardItem.mouseChildren = true;
				awardItem.mouseEnabled = true;
			}
		}
		/**
		 *注册事件 
		 * 
		 */	
		public function addEvtListener():void
		{
			closeBtn.addEventListener(MouseEvent.CLICK,closeH);
		}
		/**
		 *关闭 
		 * @param e
		 * 
		 */		
		private function closeH(e :MouseEvent):void
		{
			if(this.parent)
			{
				this.parent.removeChild(this);
			}
		}
		/**
		 *删除事件 
		 * 
		 */	
		public function removeEvtListener():void
		{
			closeBtn.removeEventListener(MouseEvent.CLICK,closeH);
		}
		/**
		 *销毁 
		 * 
		 */	
		public function destroyView():void
		{
			removeEvtListener();
			for each(var awardItem :AwardItem in itemList)
			{
				awardItem.destroyView();
				awardItem = null;
			}
			itemList = null;
		}
	}
}